<%@ page contentType="text/html;charset=UTF-8" %>

<!DOCTYPE html>
<html>
<head>
	<title>序列管理</title>
	<%@ include file="/common/meta.jsp" %>
    <%@ include file="/common/import.jsp" %>
	<!-- <link rel="stylesheet" type="text/css" href="${ctx}/js/easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="${ctx}/js/easyui/themes/demo.css">
	 -->
	<script type="text/javascript">
		$(function(){
			$('#seqList').datagrid({
				title:'序列管理', //标题
				url:'${ctx}/seq/core/list!data.action',
				loadMsg:'数据载入中，请稍后……',
				nowrap: false,
				striped: true,
				collapsible:true,				
				fitColumns: true,
				pagination:true,
				singleSelect:true,
				rownumbers:true,
				remoteSort: false,
				pageList:[5,10,20,30,50,100],
				pageSize:10,
				idField:'seqEname',
				pagination:true,//分页属性
				queryParams:{}, //查询条件
				columns:[[
				    {field:'seqEname',title:'序列英文名称',width:100,sortable:true,
						sorter:function(a,b){
							return (a>b?1:-1);
						}
					},
					{field:'seqCname',title:'序列中文名称',width:100,sortable:true,
						sorter:function(a,b){
							return (a>b?1:-1);
						}
					},
					{field:'startValue',title:'开始值',width:100,sortable:true,
						sorter:function(a,b){
							return (a>b?1:-1);
						}
					},
					{field:'stepValue',title:'增长值',width:100,sortable:true,
						sorter:function(a,b){
							return (a>b?1:-1);
						}
					},
					{field:'nextValue',title:'当前值',width:100,
						sorter:function(a,b){
							return (a>b?1:-1);
						}
					},
					{field:'firstGetTime',title:'首次获取时间',width:100,
						sorter:function(a,b){
							return (a>b?1:-1);
						}
					},
					{field:'lastGetTime',title:'最后获取时间',width:100,
						sorter:function(a,b){
							return (a>b?1:-1);
						}
					},
					{field:'updateCount',title:'更新次数',width:100,
						sorter:function(a,b){
							return (a>b?1:-1);
						}
					}
				]],
				toolbar:[{
					text:'增加',
					iconCls:'icon-add',
					handler:function(){
						saveCate();
					}
				},'-',{
					text:'删除',
					iconCls:'icon-remove',
					handler:function(){
						deleteCate();
					}
				},'-',{
					text:'修改',
					iconCls:'icon-edit',
					handler:function(){
						editCate();
					}
				},'-',{
					text:'刷新',
		              iconCls:'icon-reload',
		              handler:function(){
		            	  cateReload();
		             }
				}
				]	
			});		
		});

		// 进入增加页面
		function saveCate(){
			$('#saveFrame').html('');			
			var url = '${ctx}/seq/core/add.action';				
			$('#saveFrame').attr("title",'');
			$('#saveFrame').attr("src",url);
			$('#saveDiv').window('open');			
		}
		
		// 点击取消按钮，关闭添加窗口
		function colseAdd(){
			$('#saveDiv').window('close');
		}
		// 刷新列表
		function cateReload(){
			$('#seqList').datagrid('reload');
		}
		// 判断是否选中一条记录
		function getSelected(){
			var selected = $('#seqList').datagrid('getSelected');
			if (selected){
				return selected;
			}else{
				$.messager.alert('提示', '请选择要操作的数据', 'info');
			}
		}
		
		// 进入修改页面
		function editCate(){
			var node = getSelected();		
			if (node){	
				var url = '${ctx}/seq/core/add.action?id='+node.seqEname;
				$('#saveFrame').attr("title",node.seqCname);
				$('#saveFrame').attr("src",url);
				$('#saveDiv').window('open');
			}
		}
		
		//删除，物理删除
		function deleteCate(){					
			var node = getSelected();	
			if(node){
		    	$.messager.confirm('确认','您确定要删除:<font color=red>'+node.seqCname+'</font> ？',function(r){
		        	if(r){
		        	   if(node.updateCount > 0){
		        		   $.messager.alert('提示消息', '要删除的记录属于使用中的序列，不能删除！', 'info');
                    		return false;
		        	   }else{
						$.ajax({
							type: "post",
							url: "${ctx}/seq/core/del.action?id="+node.seqEname,
							dataType: "json",
							success: function(data){
								var result = data;//jQuery.parseJSON(data);
	    						if(result.flag=='T'){
									$.messager.alert('结果', '操作成功', 'info');	
								    var rowIndex = $('#seqList').datagrid('getRowIndex',node);								
								    $('#seqList').datagrid('deleteRow', rowIndex);	
	    						}else if(result.flag=='F'){
	    							$.messager.alert('结果', result.msg, 'info');	
	    						}else{
	    							$.messager.alert('结果', '操作失败，请重试', 'error');	
	    						}
							}
						});
		        	   }
		          	}
		       });		             		
		    }	
		}

	</script>
</head>
<body>

	<table id="seqList"></table>
	
	<!-- 添加窗口 -->
	<div id="saveDiv" class="easyui-window" title="序列定义" style="padding:5px;width: 670px;height:300px;"
    	iconCls="icon-search" closed="true" maximizable="false" minimizable="false" collapsible="false">
   		<iframe frameborder="0"  id="saveFrame" height="100%" width="100%" scrolling="No" frameborder="0" ></iframe>
    </div>
</body>
</html>